home *** CD-ROM | disk | FTP | other *** search
/ Cre@te Online 2000 December / Cre@teOnline CD05.iso / MacSoft / XML Instance.sea / XML Instance / Required / plugins / HTMLWindow.jar / horst / FrameSetView.class (.txt) < prev    next >
Encoding:
Java Class File  |  2000-03-18  |  7.8 KB  |  243 lines

  1. package horst;
  2.  
  3. import java.awt.Color;
  4. import java.awt.Component;
  5. import java.awt.Dimension;
  6. import java.awt.Graphics;
  7. import java.awt.Rectangle;
  8. import java.awt.Shape;
  9. import java.net.URL;
  10. import java.util.StringTokenizer;
  11. import java.util.Vector;
  12. import javax.swing.JComponent;
  13. import javax.swing.JScrollPane;
  14.  
  15. public class FrameSetView extends BlockView {
  16.    FrameSetPanel m_panel;
  17.    Component[] m_framesetChildren;
  18.    URL[] m_frameURLs;
  19.    FrameConstraint[] m_constraints;
  20.    int m_orientation = 0;
  21.    boolean m_bLoadedFrames;
  22.  
  23.    public FrameSetView(View parent, Element e, HTMLPane container) {
  24.       super(parent, e, container);
  25.    }
  26.  
  27.    Object getFrame(int idx) {
  28.       if (this.m_framesetChildren != null && this.m_framesetChildren.length > idx && this.m_framesetChildren[idx] instanceof HTMLWindow) {
  29.          HTMLWindow wnd = (HTMLWindow)this.m_framesetChildren[idx];
  30.          if (wnd != null) {
  31.             return ((JScrollPane)wnd).getViewport().getView();
  32.          }
  33.       }
  34.  
  35.       return null;
  36.    }
  37.  
  38.    HTMLPane getFrame(String frameName) {
  39.       if (frameName != null) {
  40.          if (frameName.equalsIgnoreCase("_self")) {
  41.             return super.m_container;
  42.          }
  43.  
  44.          if (frameName.equalsIgnoreCase("_top")) {
  45.             HTMLPane p = super.m_container;
  46.  
  47.             while(p != null) {
  48.                if (p instanceof HTMLPane && !p.m_props.m_bIsFrame) {
  49.                   return p;
  50.                }
  51.  
  52.                Component parent = ((Component)p).getParent();
  53.                if (parent == null) {
  54.                   HTMLPane hp = null;
  55.                   break;
  56.                }
  57.             }
  58.  
  59.             return null;
  60.          }
  61.  
  62.          for(int i = 0; i < this.m_framesetChildren.length; ++i) {
  63.             if (this.m_framesetChildren[i] instanceof HTMLWindow) {
  64.                HTMLWindow p = (HTMLWindow)this.m_framesetChildren[i];
  65.                HTMLPane html = p.getHTMLPane();
  66.                String name = html.m_props.m_frameName;
  67.                if (name != null && name.equals(frameName)) {
  68.                   return html;
  69.                }
  70.             }
  71.          }
  72.       }
  73.  
  74.       return null;
  75.    }
  76.  
  77.    protected int getMinimumSpan(int axis) {
  78.       return this.getPreferredSpan(axis);
  79.    }
  80.  
  81.    protected int getPreferredSpan(int axis) {
  82.       Dimension dim = super.m_container.getBrowserDimension();
  83.       return axis == 1 ? dim.width : dim.height;
  84.    }
  85.  
  86.    protected void init() {
  87.       this.m_bLoadedFrames = false;
  88.       this.m_panel = new FrameSetPanel();
  89.       super.m_container.add(this.m_panel);
  90.       this.m_panel.setBackground(Color.white);
  91.       int nCount = super.m_elem.getElementCount();
  92.       FrameSetLayout layoutManager = new FrameSetLayout();
  93.       boolean bAddSplitterBars = true;
  94.       String atts = (String)super.m_elem.getAttribute("frameborder");
  95.       if (!super.m_container.m_preferences.m_bAlwaysSizableFrames && atts != null && (atts.equalsIgnoreCase("0") || atts.equalsIgnoreCase("no"))) {
  96.          layoutManager.setAlwaysConstraintLayout(true);
  97.          bAddSplitterBars = false;
  98.       }
  99.  
  100.       Vector temp = new Vector();
  101.       Vector urlVec = new Vector();
  102.       this.m_framesetChildren = new JComponent[nCount];
  103.       URL refURL = super.m_elem.getDocument().getBaseURL();
  104.  
  105.       for(int i = 0; i < nCount; ++i) {
  106.          Element elem = super.m_elem.getElementAt(i);
  107.          if (elem.getType() == 36) {
  108.             HTMLWindow htmlWnd = new HTMLWindow(false);
  109.             HTMLPane html = htmlWnd.getHTMLPane();
  110.             html.m_preferences.m_bShowToolTip = false;
  111.             html.m_props.m_bIsFrame = true;
  112.             html.m_props.m_framesetView = this;
  113.             html.m_props.m_frameBaseDocument = super.m_container.getDocument();
  114.             String name = (String)elem.getAttribute("name");
  115.             if (name != null) {
  116.                html.m_props.m_frameName = name;
  117.             }
  118.  
  119.             String src = (String)elem.getAttribute("src");
  120.             URL url = null;
  121.             if (refURL != null) {
  122.                url = Utilities.getURL(refURL, src);
  123.             } else {
  124.                url = Utilities.getURL(src);
  125.             }
  126.  
  127.             if (url != null) {
  128.                html.openPage(url);
  129.             }
  130.  
  131.             urlVec.addElement(url);
  132.             temp.addElement(htmlWnd);
  133.          } else if (elem.getType() == 35) {
  134.             FrameSetView fv = (FrameSetView)super.m_container.m_viewFactory.createView((View)null, elem, super.m_container);
  135.             temp.addElement(fv.m_panel);
  136.          }
  137.       }
  138.  
  139.       this.m_framesetChildren = new Component[temp.size()];
  140.       temp.copyInto(this.m_framesetChildren);
  141.       this.m_frameURLs = new URL[urlVec.size()];
  142.       urlVec.copyInto(this.m_frameURLs);
  143.       if ((atts = (String)super.m_elem.getAttribute("cols")) != null) {
  144.          layoutManager.setOrientation(0);
  145.          this.parseAttributes(atts);
  146.       } else if ((atts = (String)super.m_elem.getAttribute("rows")) != null) {
  147.          layoutManager.setOrientation(1);
  148.          this.parseAttributes(atts);
  149.       } else {
  150.          layoutManager.setOrientation(0);
  151.          this.m_constraints = new FrameConstraint[this.m_framesetChildren.length];
  152.  
  153.          for(int i = 0; i < this.m_framesetChildren.length; ++i) {
  154.             this.m_constraints[i] = new FrameConstraint();
  155.             if (i == 0) {
  156.                this.m_constraints[i].percent = 1.0F;
  157.             } else {
  158.                this.m_constraints[i].percent = 0.0F;
  159.             }
  160.          }
  161.       }
  162.  
  163.       this.m_panel.setLayout(layoutManager);
  164.  
  165.       for(int i = 0; i < this.m_framesetChildren.length; ++i) {
  166.          layoutManager.setConstraints(this.m_framesetChildren[i], this.m_constraints[i]);
  167.          this.m_panel.add(this.m_framesetChildren[i]);
  168.          if (bAddSplitterBars && i != this.m_framesetChildren.length - 1 && this.m_framesetChildren.length > 1) {
  169.             FrameSplitterBar splitbar = new FrameSplitterBar(this.m_orientation);
  170.             splitbar.setResizable(true);
  171.             this.m_panel.add(splitbar);
  172.          }
  173.       }
  174.  
  175.    }
  176.  
  177.    protected Rectangle layout(int x, int y, int width, LayoutInfo info) {
  178.       if (!super.m_container.getFramesEnabled()) {
  179.          super.m_bounds.setBounds(0, 0, 0, 0);
  180.          return super.m_bounds;
  181.       } else {
  182.          Dimension d = super.m_container.getBrowserDimension();
  183.          super.m_bounds.setBounds(x, y, width, d.height);
  184.          this.m_panel.setBounds(super.m_bounds);
  185.          return super.m_bounds;
  186.       }
  187.    }
  188.  
  189.    protected void makeChildren(ViewFactory factory) {
  190.    }
  191.  
  192.    public void paint(Graphics g, Shape alloc) {
  193.       this.m_panel.invalidate();
  194.    }
  195.  
  196.    void parseAttributes(String attStr) {
  197.       if (attStr != null) {
  198.          StringTokenizer st = new StringTokenizer(attStr, ",");
  199.          int nCols = st.countTokens();
  200.          this.m_constraints = new FrameConstraint[nCols];
  201.          if (nCols > 0) {
  202.             for(int i = 0; st.hasMoreTokens(); ++i) {
  203.                String token = st.nextToken();
  204.                this.m_constraints[i] = new FrameConstraint();
  205.                Integer val = null;
  206.                if ((val = Utilities.parseInteger(token, '%')) != null) {
  207.                   this.m_constraints[i].type = 1;
  208.                   this.m_constraints[i].percent = (float)val / 100.0F;
  209.                } else if ((val = this.parseWildCard(token)) != null) {
  210.                   this.m_constraints[i].type = 2;
  211.                   this.m_constraints[i].wildcard = val;
  212.                } else {
  213.                   val = Utilities.getInteger(token);
  214.                   this.m_constraints[i].type = 0;
  215.                   this.m_constraints[i].pixels = val;
  216.                }
  217.             }
  218.          }
  219.       }
  220.  
  221.    }
  222.  
  223.    Integer parseWildCard(String token) {
  224.       Integer val = null;
  225.       int idx;
  226.       if ((idx = token.indexOf(42)) != -1) {
  227.          try {
  228.             token = token.substring(0, idx).trim();
  229.             val = new Integer(token);
  230.          } catch (NumberFormatException var4) {
  231.             return new Integer(1);
  232.          }
  233.       }
  234.  
  235.       return val;
  236.    }
  237.  
  238.    protected void reset() {
  239.       this.m_bLoadedFrames = false;
  240.       super.reset();
  241.    }
  242. }
  243.